import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { TBacklog } from 'src/entities/backlog.entity';

export class BacklogRepository {
  constructor(
    @InjectRepository(TBacklog)
    private backlogRepository: Repository<TBacklog>,
  ) {}

  // 查询列表
  async queryBacklogListRepository(repository: any) {
    return await this.backlogRepository.find({
      where: {
        delFlag: 0,
        createdBy: repository.createdBy,
      },
    });
  }

  // 查询所有列表
  queryALlBacklogListRepository() {
    return this.backlogRepository.find();
  }

  // 增加
  async addBacklogRepository(repository: TBacklog) {
    const backlog = this.backlogRepository.create(repository);
    return this.backlogRepository.save(backlog);
  }

  // 删除
  async deleteBacklogRepository(id: number) {
    return this.backlogRepository.update(id, { delFlag: 1 });
  }

  // 修改
  async updateBacklogRepository(id: number, backlog: TBacklog) {
    return this.backlogRepository.update(id, backlog);
  }
}
